<?php

namespace App\Models;

// use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel;

use SmallRuralDog\Admin\Traits\ModelTree;

class Region extends BaseModel
{
    use ModelTree;

    protected $primaryKey = 'id';

    protected $table = "regions";

    protected $fillable = ['id', 'parent_id', 'code', 'name', 'created_at', 'updated_at'];

    // protected $parentColumn = '1';

    // protected $orderColumn = 'id';

    // protected $casts = [
    //     'is_directory' => 'boolean',
    // ];

    // 构造函数中初始化 protected 属性
    public function __construct()
    {
        $this->orderColumn = 'id';
    }

    protected $casts = [
        'created_at' => 'Y-m-d H:i:s',
        'updated_at' => 'Y-m-d H:i:s',
    ];



    public function children()
    {
        return $this->hasMany(get_class($this), 'parent_id')->orderBy('id');
    }

}
